package com.calefk.util {

	public class ValidateField {
		
		// la expresion debe comenzar con /^ y terminar con $i
		/*
			* D.N.I.: ^\d{1,8}$
			* Entero: ^(?:\+|-)?\d+$
			* Real: ^(?:\+|-)?\d+\.\d*$
			* Hora: ^(0[1-9]|1\d|2[0-3]):([0-5]\d):([0-5]\d)$
			* Fecha: ^([012][1-9]|3[01])(/|-)(0[1-9]|1[012])\2(\d{4})$
			* Email: (^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*)@ ([0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3})$
			* HTML Tags: ^\<[^\>]#\>$
			* LINK: <a[^>]*href="[^\s"]+"[^>]*>[^<]*<\/a> 
			* IP: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$
			* Nombre: ^[a-zäöü ][a-zäöüß ]{2,} [a-zäöü\-\.][a-zäöüß\-\.]{2,}$
			* Calle: ^[a-zäöüß ]([a-zäöüß ]\-?)+[a-zäöüß ]\.? \d{1,3}\w?$
			* URL: ^[a-z0-9_\-]+(\.[_a-z0-9\-]+)*@([_a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel)$
			* ZipCode: ^\d{5}$ 
		*/
		
		public static function isValidInt(s:String):Boolean {
			var intEx:RegExp	= /^(?:\+|-)?\d+$/i;
			return intEx.test(s); 
		}
		
		public static function isLen(s:String , n:int):Boolean {
			return (s.length == n);
		}
		
		public static function isMinLen(s:String , n:int):Boolean {
			return (s.length >= n);
		}
		
		public static function isValidMail(email:String):Boolean{ 
			var emailEx:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i; 
			return emailEx.test(email); 
		}
		
		public static function isValidDNI(dniS:String):Boolean {
			var dniEx:RegExp = /^\d{1,8}$/i; 
			return dniEx.test(dniS); 			
		}
		
		public static function trim(str:String):String {
          return str.replace(/^\s*(.*?)\s*$/g, "$1");
		}
		
	}

}